<template>
  <div class="cavas">
    <iframe ref="iframe" class="panel" :src="src"></iframe>
  </div>
</template>
<script lang="ts">
import {
  Component,
  Vue,
  Prop,
  Watch,
  Inject,
  Emit,
} from "vue-property-decorator";
import axios from "axios";
import { homeApi, userApi } from "@cloudpivot/api";

@Component({
  name: "newZC",
  components: {},
})
export default class newZC extends Vue {
  src: string = sessionStorage["selfUrl"]
    //"/mobile/#/form/detail?schemaCode=GYSK&sheetCode&return=%2Fapps%2Fapps-form-list%2FGYSK";
  objctid: string = "";
  iHandle: any;
  user: any;

  async mounted() {
    this.user = window.sessionStorage.getItem("user");
    if (this.user) {
      this.user = JSON.parse(this.user);
    } else {
      this.user = { id: "", name: "" };
    }
    var userinfo: any = await userApi.getUserInfo(this.user.id);
    this.$refs.iframe.src = sessionStorage["selfUrl"]

    // let that = this;

    // if (that.iHandle) {
    //   clearInterval(that.iHandle);
    // }

    // that.checkGYSStatus();
    // that.iHandle = setInterval(async function () {
    //   that.checkGYSStatus();
    // }, 500);
  }

  beforeDestroy() {
    if (this.iHandle) {
      clearInterval(this.iHandle);
    }
  }

  async checkGYSStatus() {
    let that = this;
    await axios
      .get(
        "/api/zcxtHomePage/isExist?userId=" +
          that.user.id
      )
      .then(async (res: any) => {
        if (res.data.flag) {
          await axios
            .get(
              "/api/zcxtHomePage/getGYSKIdByUserId?userId=" +
                that.user.id
            )
            .then(async (res: any) => {
              if (res.errcode == 0) {
                if (that.objctid != res.data) {
                  debugger;
                  that.objctid = res.data;
                  setTimeout(function () {
                    that.$refs.iframe.src = sessionStorage["selfUrl"]
                      // "/mobile/#/form/detail?sheetCode=GYSK&objectId=" +
                      // res.data +
                      // "&schemaCode=GYSK&isWorkFlow=false&return=%2Fapps%2Fapps-form-list%2FGYSK";
                  }, 200);
                }
              } else {
                if (that.objctid != "") {
                  that.objctid = "";
                }
              }
            });
        } else {
          sessionStorage["homeSwitch"] = 2;
          that.$router.push({ name: "homeZC" }).catch((err: any) => {
            err;
          });
        }
      });
  }
}
</script>
<style lang="less" scoped>
.cavas {
  width: 100vw;
  padding: 5px;
  height: calc(100vh - 53px);
  background-color: #f7f7fa;
  overflow: hidden;

  .panel {
    background-color: #fff;
    width: 100%;
    height: 100%;
    border: none;
    border-top: 2px solid rgba(161, 218, 255, 1);
    border-radius: 5px 5px 0 0;
  }
}
</style>